import React from 'react';
import { inject, observer } from "mobx-react";
import { Icon, Button, message, Spin, Modal, Tooltip, Popover } from 'antd'
import { WeaTools, WeaPopoverHrm, WeaLocaleProvider, WeaTab, WeaNewScroll, WeaTop, WeaTag, WeaDropdown, WeaRightMenu, WeaDialog } from 'ecCom'
import { routerShape } from 'react-router';
import { toJS } from 'mobx';
import ButtonTop from './goalcomponent/ButtonTop';
import CubeLayout from "../../../govern/components/E9/cubeLayout";
import GoalBaseFiled from './goaldetail/GoalBaseFiled';
import GoalCommet from './goaldetail/GoalCommet';
import GoalOperateLog from './goaldetail/GoalOperateLog';
import GoalRelateInfo from './goaldetail/GoalRelateInfo';
import GoalSubGoal from './goaldetail/GoalSubGoal';
import GoalAdd from './GoalAdd';
import GoalShare from './goaldetail/GoalShare';
import * as goalDetailApis from '../../apis/goal/goalDetail'
import TagChoiceBox from '../../public/tag/TagChoiceBox'
import * as Util from "../../util/Util";
import dict from '../../util/wea-workrelate-file';
dict.addWindowFunc();
const getLabel = WeaLocaleProvider.getLabel;
const { ButtonSelect } = WeaDropdown;
@inject("goalDetailStore", "goalCommonStore")
@observer
export default class GoalDetail extends React.Component {
    static contextTypes = {
        router: routerShape
    }
    constructor(props) {
        super(props);
        this.state = {
            viewHeight: Util.getCurrentHeight(), //屏幕高度
            topTab: [  //分页选择
                {
                    title: getLabel(81711, '基本信息'),
                    viewcondition: "0"
                },
                {
                    title: getLabel(508864, '下级目标'),
                    viewcondition: "1"
                },
                {
                    title: getLabel(383491, '相关信息'),
                    viewcondition: "2"
                },
                {
                    title: getLabel(83596, '反馈信息'),
                    viewcondition: "3"
                },
                {
                    title: getLabel(383654, '共享列表'),
                    viewcondition: "5"
                },
                {
                    title: getLabel(32061, '操作日志'),
                    viewcondition: "4"
                }
            ],
            tabKey: "0", //tab主键
            dropData: [{ key: '1', show: getLabel(32136, '批量删除') },
            { key: '2', show: getLabel(390705, '批量标记') }],
            collectParams:{},
            shareVisiable:false //共享列表是否展示
        }
    }

    //一些初始化请求
    componentWillMount() {
        const { goalDetailStore: { setIconType } } = this.props;
        if (Util.getParams('id') && Util.getParams('id') != '') {
            let key = Util.getParams('id');
            setIconType('2');
            this.renderDetail(key);
        } else {
            this.renderDetail();
        }
    }

    //重新刷新页面
    componentWillReceiveProps(nextProps) {
        if (this.props.detailKey != nextProps.detailKey || (this.props.locationKey && this.props.locationKey != nextProps.locationKey)) {
            this.renderDetail(nextProps.detailKey)
        }
    }

    componentDidMount() {
        const { goalDetailStore } = this.props;
        goalDetailStore.loading = false;
    }
    componentDidUpdate(){
        if(location.href.indexOf("/main/workrelate/goal/goalDetail")>-1){
            const { goalDetailStore } = this.props;
            document.title=goalDetailStore.detailData.name;
        }
    }

    //设置右键收藏
    setCollection = (id,tabKey) =>{
        let collectParams = {
            favname: getLabel(507890, '目标详情'),
            favouritetype: 5,
            link: '/spa/workrelate/static/index.html?#/main/workrelate/goal/goalDetail?id='+id+'&tabkey='+tabKey,
            importantlevel: 1,
        }
        this.setState({collectParams})
    }

    //绑定子组件的方法
    onRef = (ref) => {
        this.child = ref
    }

    renderDetail = (detailKey) => {
        const { goalDetailStore, goalCommonStore } = this.props;
        const { setDetailKey, initData } = goalDetailStore;
        const { condtype, typeId, orgId} = goalCommonStore;
        let key = detailKey ? detailKey : this.props.detailKey;
        setDetailKey(key)
        let tabkey = Util.getParams('tabkey');
        this.setCollection(key,tabkey||'0');
        if (goalCommonStore.isFocusFeedBack) {
            this.changeTabKey("3")
        } else {
            this.changeTabKey(tabkey || "0")
        }
        if (Util.isEmpty(key)) {
            return;
        }
        //加载页面详情
        goalDetailStore.initForm({
            goalId: key, doback: () => {
                this.getDetailView({
                    goalId: key, condtype , doback: (date) => {    //date 用户最后的浏览时间
                        let feedBackParams = { goalId: key, viewdate: date };
                        let subParams = { goalId: key, type: "father" };
                        initData(feedBackParams, subParams)
                        this.getFileCateGory();
                    }
                });
            }
        });
    }


    //获取文件的上传目录
    getFileCateGory = () => {
        WeaTools.callApi('/api/workrelate/goal/fileCategory', 'GET', {}).then((data) => {
            const { goalDetailStore: { setCategory, setMaxUploadSize } } = this.props;
            if (data.status == 1) {
                // this.setState({category:data.secId , maxUploadSize: data.maxsize});
                setCategory(data.secId)
                setMaxUploadSize(data.maxsize)
            }
        });
    }

    //获取目标的详细信息
    getDetailView = (params) => {
        const { goalDetailStore } = this.props;
        goalDetailStore.getDetailView(params);

    }

    //处理头部点击事件
    topClick = (id, type, value) => {
        const { goalDetailStore, goalCommonStore } = this.props;
        let { isSpecial, topBtns, setButton, detailData } = goalDetailStore;
        if (type == 'isSpecial') {   //处理关注
            let params = {
                goalId: id,
                special: value,
                doback: () => {
                    this.doCallBack('special')
                }
            };
            if (value == 1) {
                isSpecial = true;
            } else {
                isSpecial = false;
            }
            goalDetailStore.updateGoalSpecial(params);
        } else if (type == 'complete') {  //完成
            let obj = {
                id: '2',
                key: 'revoker',
                value: [getLabel(23757, '撤销'), getLabel(1981, '已撤销')],
                type: ['ghost', 'primary'],
                valid: 0,
            }
            let params = {
                goalId: id,
                doback: () => {
                    this.doCallBack('status')
                }
            };
            if (value == 1) {
                params.status = '2';
                Util.removeAarry(topBtns, obj);
                goalDetailStore.editStatus(params);
            } else {
                params.status = '1';
                Util.removeAarry(topBtns, obj);
                goalDetailStore.editStatus(params);

            }
            detailData.status = params.status
            this.renderDetail(id);
        } else if (type == 'revoker') {
            let obj = {
                id: '1',
                key: 'complete',
                value: [getLabel(555, '完成'), getLabel(23774, '已完成')],
                type: ['ghost', 'primary'],
                valid: 0,
            }
            let params = {
                goalId: id,
                doback: () => {
                    this.doCallBack('status')
                }
            };
            if (value == 1) {
                params.status = '3'
                Util.removeAarry(topBtns, obj);
                // this.inputChange('status','3');
                goalDetailStore.editStatus(params);
            } else {
                params.status = '1'
                topBtns.splice(1, 0, obj);
                goalDetailStore.editStatus(params);
            }
            detailData.status = params.status
        } else if (type == 'feedback') {
            goalCommonStore.setIsFocusFeedBack(true)
            this.changeTabKey("3")
        } else {
            this.topDelete(id)
        }
        setButton(isSpecial, detailData.status, detailData.canedit,detailData.canDelete)
    }


    //顶部删除
    topDelete = (id) => {
        Modal.confirm({
            title: getLabel(15172, '系统提示'),
            content: getLabel(127574, '确定删除吗？'),
            onOk: () => {
                this.deleteGoal(id);
            },

        });
    }

    //删除目标
    deleteGoal = (id) => {
        const { goalDetailStore } = this.props;
        let params = {
            goalId: id,
            status: '4',
            doback: (goalId) => {
                if(goalDetailStore.iconType == "2"){//直接打开  删除功能就关闭当前窗口
                    window.opener=null;
                    window.open('','_self');
                    window.close();
                }
                if (typeof this.props.onEditSuccess === 'function') {
                    let optparams = {};
                    optparams.optkey = id;
                    optparams.opttype = 'del';
                    this.props.onEditSuccess(optparams);
                }
            }
        }
        goalDetailStore.editStatus(params);

    }

    //回调函数 调用goalMain.js里面的方法
    doCallBack = (type, newparams, data, cstatus) => {
        let optparams = {};
        const { goalDetailStore } = this.props;
        const { detailKey } = goalDetailStore;
        if (data && data.length > 0) {
            optparams.optkey = data;
        } else {
            optparams.optkey = detailKey;
        }
        if (type == 'special' || type == 'status') {  //关注  标记完成 标记进行回调
            let special = goalDetailStore.isSpecial;
            let status = goalDetailStore.detailData.status;
            optparams.opttype = "update";
            optparams.comsbtn = this.callBackButton(special, status);
            optparams.status = status;
            if (typeof this.props.onEditSuccess === 'function') {
                this.props.onEditSuccess(optparams)
            }
        } else if (type == 'enddate' || type == 'principalid' || type == 'addfb') {
            let params = {};
            params.enddate = goalDetailStore.detailData.enddate; //结束时间
            if (!Util.isEmpty(goalDetailStore.detailData.principalid_arr[0])) {
                params.principalid = goalDetailStore.detailData.principalid_arr[0].name;  //责任人
            } else {
                params.principalid = ''
            }
            params.key = detailKey;
            params.feedbackcount = '(' + goalDetailStore.feedBackData.list.length + ')'  //反馈信息
            if (typeof this.props.onEditSuccess === 'function') {
                this.props.onEditSuccess(params, 2)
            }
        } else if (type == "name") {//目标名称修改回调
            optparams.title = goalDetailStore.detailData[type];
            optparams.opttype = 'update';
            if (typeof this.props.onEditSuccess === 'function') {
                this.props.onEditSuccess(optparams)
            }
        } else if (type == "delsub") {//批量删除回调
            optparams.opttype = type;
            optparams.delData = newparams;
            if (typeof this.props.onEditSuccess === 'function') {
                this.props.onEditSuccess(optparams)
            }
        } else if (type == "tag") { //标签更新回调
            optparams.opttype = "update";
            optparams.tags = newparams;
            if (typeof this.props.onEditSuccess === 'function') {
                this.props.onEditSuccess(optparams)
            }
        } else if (type == "batchtag") {//批量更新任务标签
            optparams.opttype = type;
            optparams.optkeys = cstatus;
            optparams.tags = newparams;
            if (typeof this.props.onEditSuccess === 'function') {
                this.props.onEditSuccess(optparams)
            }
        } else if(type == "parentid" || type == "remark" || type == "partnerid" || type == "cateid" ){ //详情更新  上级目标 责任人 参与人 日期 分类  描述 回调
            if (typeof this.props.onEditSuccess === 'function') {
                this.props.onEditSuccess(optparams,3)
            }
        } else {
            if (!Util.isEmpty(newparams) || !Util.isEmpty(data)) {
                this.onCallBackSuccess(newparams, data)   //弹出层  新增页面回调成功
            }
        }
    }

    //弹出层  新增页面回调成功
    onCallBackSuccess(optparams, data) {
        const { goalDetailStore } = this.props;
        const { detailKey } = goalDetailStore;
        let key = optparams.optkey;   //暂存optkey
        if (data && data.length > 0) {  //更新详情树级节点
            if (data[0].id != detailKey) {
                optparams.optkey = data[0].id;
                optparams.opttype = "addchild";
                goalDetailStore.setOptparams(optparams);  //   
            } else {
                goalDetailStore.setOptparams(optparams);
            }
        } else {
            goalDetailStore.setOptparams(optparams);
        }
        if (typeof this.props.onEditSuccess === "function") {
            optparams.optkey = key;
            optparams.opttype = "dialogAdd";
            this.props.onEditSuccess(optparams);
        }
    }

    //回调按钮的设置
    callBackButton = (special, status) => {
        const { goalDetailStore: { detailData } } = this.props
        let comsbtn = [];
        let arr = {};
        comsbtn.push({
            title: getLabel(21950, '反馈'),
            com: getLabel(21950, '反馈'),
            type: "addfb",
            icon: "message"
        });

        if (detailData.canDelete) {  //拥有删除权限
            comsbtn.push({
                title: getLabel(91, '删除'),
                com: getLabel(91, '删除'),
                type: "delete",
                icon: "delete"
            });
        }
        comsbtn.push({
            title: getLabel(516459, '标记标签'),
            com: getLabel(516459, '标记标签'),
            type: "tag",
            iicon: "icon-coms02-Label"
        });
        comsbtn.push({
            title: special && special == true ? getLabel(26938, '取消关注') : getLabel(26939, '添加关注'),
            com: special && special == true ? getLabel(26938, '取消关注') : getLabel(25436, '关注'),
            type: special && special == true ? "canclespecial" : "special",
            icon: special && special == true ? "star" : "star-o"
        });
        if (detailData.canedit) {
            if (status == 2) {
                comsbtn.push({
                    title: getLabel(508575, '当前状态完成,点击设置未完成'),
                    com: getLabel(382565, '标记进行'),
                    type: "progress",
                    icon: "check-circle-o"
                });
            } else if (status == 3) {
                comsbtn.push({
                    title: getLabel(508799, '当前状态为撤销,点击设置进行中'),
                    com: getLabel(382565, '标记进行'),
                    type: "progress",
                    icon: "check-circle-o"
                });
            } else {
                comsbtn.push({
                    title: getLabel(508800, '当前状态为未完成,点击设置完成'),
                    com: getLabel(382564, '标记完成'),
                    type: "complete",
                    icon: "check"
                });
            }
        }
        return comsbtn;
    }

    //改变tab的key
    changeTabKey = (key) => {
        const { goalDetailStore, goalCommonStore } = this.props;
        const { detailData,detailKey } = goalDetailStore;
        const { setIsFocusFeedBack } = goalCommonStore;
        if (this.state.tabKey != key) {
            goalDetailStore.loading = true;
        }
        if (key == "3") {  //反馈聚焦
            setIsFocusFeedBack(true);
        }
        if (key == "0") { //建模loading设为true
            goalDetailStore.cubeLoading = true;
            this.resetUrlKey()
        }
        this.setCollection(toJS(detailKey),key);
        this.setState({ tabKey: key })
    }

    menuOnClick(key) {
        const { goalDetailStore } = this.props;
        goalDetailStore.dropSelectedKey = key;
    }

    btnOnClick(key) {
        const { goalDetailStore, goalCommonStore } = this.props;
        const { condtype } = goalCommonStore;
        if (key == 1) {
            let _sublist = goalDetailStore.subGoalList;
            let goalIds = Util.getDataListIds(_sublist, true, 4);
            if (goalIds == "") {
                message.warning(getLabel(501159, '请选择要操作的数据'));
                return;
            }
            let _this = this;
            Modal.confirm({
                title: getLabel(131329, '信息确认'),
                content: getLabel(513503, '确认要删除选中记录吗？'),
                onOk() {
                    goalDetailStore.batchDelGoal({
                        goalIds, condtype, doback: function (status) {
                            message.success(getLabel(83472, '删除成功!'), 2);
                            if (status) {
                                _this.doCallBack('delsub', Util.operateSymbol(goalIds, ',', 'del').split(","));
                                goalDetailStore.setDropDisplay(false)
                                message.success(getLabel(83472, '删除成功!'), 2);
                            }
                        }
                    });
                },
                onCancel() { },
            });
        } else {
            goalDetailStore.checkedIds = "";
            goalDetailStore.changeSubTagBoxVisible(true, 1);
        }
    }

    //调用子组件的新增方法
    onAddGoal = () => {
        this.child.onAddGoal(1)
    }

    onNodeClick = (key) => {
        if (key && key != '') {
            this.renderDetail(key);
        }
    }

    //新建dialog框关闭
    onlyClose(optparams) {
        const { goalCommonStore } = this.props;
        const { setCreatevisable } = goalCommonStore
        if (optparams) {
            if (optparams.type == 1 && typeof this.props.closeSlider === 'function') {
                this.props.closeSlider(optparams);
            } else {
                setCreatevisable(false)
            }
        } else {
            setCreatevisable(false)
        }
    }

    //生成顶部的Button
    getBtns = (detailKey, data,ecId) => {
        let btns = [];
        btns = data
        let buttons = [];
        for (let i = 0; i < btns.length; i++) {
            let current = btns[i]
            if (!Util.isEmpty(current.tip)) {
                let btn = <Tooltip ecId={`${ecId}_Tooltip@clx6f9`} title={current.tip[current.valid]}><Button ecId={`${ecId}_Button@gatapz`} id={i} type={current.type[current.valid]} ref="myButton" onClick={() => this.click(i, current.key, detailKey)}>{current.value[current.valid]}</Button></Tooltip>;
                buttons.push(btn)
            } else {
                let btn = <Button ecId={`${ecId}_Button@4ojkcr`} id={i} type={current.type[current.valid]} ref="myButton" onClick={() => this.click(i, current.key, detailKey)}>{current.value[current.valid]}</Button>;
                buttons.push(btn)
            }
        }
        return buttons;
    }

    //获取右键按钮
    getRightMenu = (detailKey,data) =>{
        let btns = data;
        let buttons = [];
        let item = {};
        for(let i = 0;i < btns.length; i++){
            let current = btns[i]
            item = {
                key:''+i,
                icon:this.getIcon(current.key,current.valid),
                content:current.tip[current.valid],
                onClick:()=>this.click(i, current.key, detailKey)
            }
            buttons.push(item);
        }
        return buttons;
    }

    //获得右键按钮图标
    getIcon = (type,valid) =>{
        if(type == "complete"){
            return <i className="icon-coms-complete" />
        }else if(type == "revoker"){
            return <i className="icon-coms-Revocation" />
        }else if(type == "delete"){
            return <i className="icon-coms-Delete" />
        }else if(type == "feedback"){
            return <i className="icon-coms-Need-feedback" />
        }else if(type == "isSpecial"){
            return valid == 0 ? <i className="icon-coms-Collection" /> : <i className="icon-coms-Collection2" />
        }
    }

    click = (id, type, detailKey) => {
        let { goalDetailStore: { topBtns } } = this.props;
        let buttons = topBtns;
        if (buttons[id].key == type) {
            if (type == "complete") {
                Modal.confirm({
                    title: getLabel(15172, '系统提示'),
                    content: buttons[id].valid == 0 ? getLabel(508754, '确认标记完成吗') : getLabel(508755, '确认标记进行吗'),
                    onOk: () => {
                        buttons[id].valid == 0 ? buttons[id].valid = 1 : buttons[id].valid = 0;
                        this.topClick(detailKey, type, buttons[id].valid)
                    },

                });

            } else if (type == "revoker") {
                Modal.confirm({
                    title: getLabel(15172, '系统提示'),
                    content: buttons[id].valid == 0 ? getLabel(516456, '确认标记撤销吗') : getLabel(508755, '确认标记进行吗'),
                    onOk: () => {
                        buttons[id].valid == 0 ? buttons[id].valid = 1 : buttons[id].valid = 0;
                        this.topClick(detailKey, type, buttons[id].valid)
                    },

                });
            } else {
                if (buttons[id].value.length == 2) {
                    if (buttons[id].valid == 0) {
                        buttons[id].valid = 1;
                    } else {
                        buttons[id].valid = 0;
                    }
                }
                this.topClick(detailKey, type, buttons[id].valid)
            }

        }
    }

    onChoiceBoxBottomClick = (type, tagList) => {
        const { changeTagChoiceBoxVisible } = this.props.goalDetailStore
        if (type == "0") {     // 取消所有标记
            changeTagChoiceBoxVisible(false)
            Modal.confirm({
                title: getLabel(386786, '信息确认'),
                content: getLabel(517867,'确认取消所有标记吗？') ,
                onOk: () => {
                    this.updateGoalTagInfo([])
                }
            })
        } else if (type == "1") {       // 确定
            this.updateGoalTagInfo(tagList)
        }
    }

    resetUrlKey() {
        //弹框更改url上的_key值
        const { pathname, search, goalDetailStore } = this.props;
        let url = `/${pathname}${search}`;
        if (pathname == undefined || search == undefined) {
            if (location.href.indexOf("/main/workrelate/goal/goalDetail") > -1) {
                url = "/main/workrelate/goal/goalDetail?id=" + goalDetailStore.detailKey;
            } else {
                url = "/main/workrelate/goal/goalIndex";
            }
        }
        this.context.router.push({
            pathname: url
        });
    }


    onGoalRelatedTagItemDelete = (event, tag) => {
        event.preventDefault()
        event.stopPropagation()

        const { detailData } = this.props.goalDetailStore
        this.updateGoalTagInfo(detailData.tagArray.filter((d, i) => d.id != tag.id))
    }

    updateGoalTagInfo = (newTaskTagList = []) => {
        const { detailData, detailKey, changeTagChoiceBoxVisible, editGoalField } = this.props.goalDetailStore
        let newIdsStr = "," + newTaskTagList.sort((a, b) => parseInt(a.id) - parseInt(b.id)).map((d, i) => d.id + "").join(",") + ","
        let oldIdsStr = "," + detailData.tagArray.sort((a, b) => parseInt(a.id) - parseInt(b.id)).map((d, i) => d.id).join(",") + ","
        let delValue = Util.ArrayDiffer(oldIdsStr, newIdsStr, 1)
        let addValue = Util.ArrayDiffer(oldIdsStr, newIdsStr.split(","), 2)
        if (newIdsStr !== oldIdsStr) {
            editGoalField({
                goalId: detailKey,
                fieldname: "tag",
                fieldvalue: newIdsStr,
                fieldtype: "str",
                logAddValue: addValue,
                logDelvalue: delValue,
                tagtype: "2",
                doback: () => {
                    changeTagChoiceBoxVisible(false)
                    // status == 1 && message.success(getLabel(31439, "更新成功"), 1)
                    detailData.tagArray = newTaskTagList;
                    this.doCallBack("tag", newTaskTagList)
                }
            })
        }
    }

    //标签设置确认回调
    onTagSettingSureClick = (datas = []) => {
        const { detailData } = this.props.goalDetailStore
        let newTagArray = []
        detailData.tagArray.forEach((et, ei) => {
            datas.forEach((dt, di) => {
                if (et.id == dt.id) {
                    et.name = dt.name
                    et.color = dt.color
                }
            })
        })
    }

    getTabButtons(ecId) {
        const { detailData, dropdisplay, dropSelectedKey } = this.props.goalDetailStore;
        const { dropData, tabKey } = this.state;
        if (detailData.cancreate && tabKey == 1) {
            return [(<Button ecId={`${ecId}_Button@iuqmpn@newsubgoal`} type="primary" onClick={this.onAddGoal}>{getLabel(508560, '新建下级目标')}</Button>),
            (<ButtonSelect ecId={`${ecId}_ButtonSelect@li7m1x@subbatchbtn`} datas={dropData} btnProps={{ disabled: dropdisplay }} selectedKey={dropSelectedKey} btnOnClick={(key) => this.btnOnClick(key)} menuOnClick={(key) => this.menuOnClick(key)} />)];
        } else {
            return [];
        }
    }

    checkList = (type, checklist) => {
        const { goalDetailStore, goalDetailStore: { changeSubTagBoxVisible, opentagtype, selectgoalid, subGoalList } } = this.props;
        let goalids = "";
        if (opentagtype == 1) {
            goalids = Util.getDataListIds(subGoalList, false, 4);
        } else {
            goalids = selectgoalid;
        }
        if (goalids == "") {
            message.warning(getLabel(501159, '请选择要操作的数据'));
            return;
        }
        changeSubTagBoxVisible(false, 1);
        let _this = this;
        if (type == "0") {     // 取消所有标记
            let _title = opentagtype == 1 ? getLabel(516448, "确定要清除选中数据的所有标签吗？") : getLabel('516445', '确认清除所有标签吗？');
            Modal.confirm({
                title: getLabel('386786', '信息确认'),
                content: _title,
                onOk: () => {
                    goalDetailStore.editGoalField({
                        fieldname: "tag", goalids: goalids, tagtype: "3", doback: function (status) {
                            if (status) {
                                _this.doCallBack('batchtag', [], "1", Util.operateSymbol(goalids, ',', 'del').split(","));
                                goalDetailStore.setDropDisplay(false)
                                // message.success(getLabel(83472, '删除成功!'), 2);
                            }
                        }
                    });
                }
            })
        } else if (type == "1") {       // 确定
            let newIdsStr = checklist.map((d, i) => d.id).join(",");
            goalDetailStore.editGoalField({
                fieldvalue: newIdsStr, fieldname: "tag", goalids: goalids, tagtype: "2", opentagtype: opentagtype, doback: function (status, msg, goalTagMap) {
                    if (status) {
                        _this.doCallBack('batchtag', goalTagMap, "2", Util.operateSymbol(goalids, ',', 'del').split(","));
                        goalDetailStore.setDropDisplay(false)
                        // message.success(getLabel(31439, '更新成功!'), 2);
                    }
                }
            });
        }
    }


    closeShareForm = () =>{
        this.setState({shareVisiable:false})
    }

    orgGoalShareSetting = () =>{
        this.setState({shareVisiable:true})
    }
    render() {
        const { goalDetailStore, goalCommonStore, openType, closeSlider, sortcond } = this.props;
        const { loading, detailData, topBtns, detailKey, iconType, hasRight, cubeLoading, cubeLayoutParame, tagChoiceBoxVisible,
            changeTagChoiceBoxVisible, taskitemTaglistPopoverVisible, changeTaskitemTaglistPopoverVisible, subtagvisible, checkedIds, changeSubTagBoxVisible, isOrgGoal } = goalDetailStore;
        const { isFocusFeedBack } = goalCommonStore;
        const { tabKey, topTab, viewHeight, collectParams, shareVisiable} = this.state;
        let cubeFlag = Object.keys(toJS(cubeLayoutParame)).length > 0;
        if (Util.isEmpty(detailKey) || !hasRight) { //没有权限操作
            return (
                <Spin ecId={`${this && this.props && this.props.ecId || ''}_Spin@nx4z4m`} spinning={loading}>
                    <div>
                        <WeaTop ecId={`${this && this.props && this.props.ecId || ''}_WeaTop@r1qinc`}
                            title={<span>{getLabel(507890, '目标详情')}</span>}
                            icon={<i className='icon-coms-implement' />} iconBgcolor={'rgb(150, 53, 138)'}
                        >
                        </WeaTop>
                        {Util.isEmpty(detailKey) && Util.renderAlertPage(getLabel(508825, '当前目标已经被删除'),'','','',this.props.ecId || '')}
                        {!hasRight && Util.renderAlertPage(getLabel(508831, '你无权查看当前目标'),'','','',this.props.ecId || '')}
                    </div>
                </Spin>
            )
        }
        return (
            <Spin ecId={`${this && this.props && this.props.ecId || ''}_Spin@rs1onu`} spinning={isFocusFeedBack ? loading : ((cubeFlag > 0 && !isOrgGoal) ? (cubeLoading || loading) : loading)}> 
                <div className="workrelate-goal-goaledit wea-workrelate-common-top">
                    <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@uqizdf`} datas={this.getRightMenu(detailKey,topBtns)} collectParams={collectParams}>
                        <WeaPopoverHrm ecId={`${this && this.props && this.props.ecId || ''}_WeaPopoverHrm@n2jtsu`} />
                        <WeaTop ecId={`${this && this.props && this.props.ecId || ''}_WeaTop@o7zp6n`}
                            title={
                                <span className="wea-workrelate-taskedit-title-wrapper">
                                    <span className="wea-workrelate-taskedit-title">
                                        <span className="wea-workrelate-taskedit-title-text" title={detailData.name ? getLabel(18238, '目标名称') + ":" + detailData.name : getLabel(508789, '任务详情')}>
                                            {detailData.name ? detailData.name : getLabel(507890, '目标详情')}
                                        </span>
                                        {/* {detailData.canedit && <Tooltip placement="bottom" title={getLabel(383654, '共享列表')} >
                                            <span style={{cursor: "pointer",margin: "5px",position: "relative"}} >
                                                <i className="icon-coms-Batch-sharing" onClick={() => this.orgGoalShareSetting()} />
                                            </span>
                                        </Tooltip>} */}
                                        <span className="wea-workrelate-taskedit-title-icons-wrapper">
                                            <span className="wea-workrelate-taskedit-title-icon-wrapper">
                                            </span>
                                            <span className="wea-workrelate-taskedit-title-icon-wrapper">
                                                <TagChoiceBox ecId={`${this && this.props && this.props.ecId || ''}_TagChoiceBox@6i3bn7`}
                                                    isDialog={false}
                                                    style={
                                                        {
                                                            width: 680,
                                                            height: 380
                                                        }
                                                    }
                                                    visible={tagChoiceBoxVisible}
                                                    checkedIds={detailData.tagArray.map((d, i) => d.id + "")}
                                                    onCallBack={this.onChoiceBoxBottomClick}
                                                    onDialogClose={() => changeTagChoiceBoxVisible(false)}
                                                    onSettingSureClick={this.onTagSettingSureClick}
                                                />
                                            </span>
                                        </span>
                                        <span className="wea-workrelate-taskedit-title-tags-wrapper">
                                            <span className="wea-workrelate-taskedit-title-tags-wrapper-abs">
                                                {
                                                    detailData.tagArray.map((tag, ti) => {
                                                        const tagShowCount = 3     // 最多只显示3个标签
                                                        if (ti < tagShowCount) {
                                                            return (
                                                                <span title={tag.name}>
                                                                    <WeaTag ecId={`${this && this.props && this.props.ecId || ''}_WeaTag@khrjh1@detail${tag.id}`}
                                                                        key={tag.id}
                                                                        id={tag.id}
                                                                        closable={true}
                                                                        onClose={(e) => this.onGoalRelatedTagItemDelete(e, { ...tag })}
                                                                        color={tag.color}
                                                                    >
                                                                        {tag.name}
                                                                    </WeaTag>
                                                                </span>
                                                            )
                                                        } else if (ti === tagShowCount) {
                                                            return (
                                                                <Popover ecId={`${this && this.props && this.props.ecId || ''}_Popover@gnwtjf@taglist`}
                                                                    // visible={true}
                                                                    trigger="hover"
                                                                    overlayClassName={"wea-workrelate-taskedit-taskitem-taglist-popover-wrapper"}
                                                                    placement={"bottomRight"}
                                                                    onVisibleChange={(visible) => changeTaskitemTaglistPopoverVisible(visible)}
                                                                    content={
                                                                        <div>
                                                                            {
                                                                                detailData.tagArray.map((tag2, ti2) => {
                                                                                    return (
                                                                                        <div title={tag2.name} className="wea-workrelate-taskedit-taskitem-taglist-popover-item">
                                                                                            <WeaTag ecId={`${this && this.props && this.props.ecId || ''}_WeaTag@o9zpzr@popover${tag2.id}`}
                                                                                                key={tag2.id}
                                                                                                id={tag2.id}
                                                                                                closable={true}
                                                                                                onClose={(e) => this.onGoalRelatedTagItemDelete(e, { ...tag2 })}
                                                                                                color={tag2.color}
                                                                                            >
                                                                                                {tag2.name}
                                                                                            </WeaTag>
                                                                                        </div>
                                                                                    )
                                                                                })
                                                                            }
                                                                        </div>
                                                                    }
                                                                >
                                                                    <i className={taskitemTaglistPopoverVisible ? "icon-coms-down" : "icon-coms-right"} style={{ marginLeft: 5 }} />
                                                                </Popover>
                                                            )
                                                        }
                                                    })
                                                }
                                            </span>
                                        </span>
                                    </span>
                                    {
                                        <span className="wea-workrelate-task-createinfo-wrapper">
                                            <Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@fk6mzn`} title={`${getLabel(882, '创建人')}:${detailData.username + "  " + getLabel(1339, '创建时间')}:${detailData.createdate + ' ' + detailData.createtime}`}>
                                                <span className="wea-workrelate-task-createinfo" dangerouslySetInnerHTML={{ __html: detailData.createrlink + detailData.createdate + ' ' + detailData.createtime }}></span>
                                            </Tooltip>
                                        </span>
                                    }
                                </span>
                            }
                            icon={iconType == '1' ? <Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@d9iyqm`} title={getLabel(508788, '关闭侧边框')}><i className='icon-coms-Right icursor-pointer' onClick={() => this.onlyClose({ type: 1 })} /></Tooltip> : <Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@izc2j6`} title={getLabel(507890, '目标详情')}><i className='icon-coms-implement' /></Tooltip>}
                            buttons={this.getBtns(detailKey, topBtns,this.props.ecId || '')}
                            iconBgcolor={iconType == '1' ? '' : 'rgb(150, 53, 138)'}
                        />
                        <WeaTab ecId={`${this && this.props && this.props.ecId || ''}_WeaTab@rz4t8c`}
                            datas={topTab}
                            keyParam="viewcondition" //主键
                            buttons={this.getTabButtons(this.props.ecId || '')}
                            selectedKey={tabKey}
                            onChange={v => this.changeTabKey(v)}
                        >
                        </WeaTab>
                        <WeaNewScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaNewScroll@1eu09f`} height={iconType == '2' ? viewHeight - 140 : viewHeight - 120} style={{ padding: '0px 10px' }} ref="goalNewScroll">
                            <div className="wea-goal-content">
                                {tabKey == "0" && <GoalBaseFiled ecId={`${this && this.props && this.props.ecId || ''}_GoalBaseFiled@rru7sg`} onNodeClick={this.onNodeClick} doCallBack={(type, optparams, data) => this.doCallBack(type, optparams, data)}></GoalBaseFiled>}
                                {tabKey == "1" && <GoalSubGoal ecId={`${this && this.props && this.props.ecId || ''}_GoalSubGoal@9endwk`} onRef={this.onRef} renderDetail={this.renderDetail} doCallBack={(type, optparams, data) => this.doCallBack(type, optparams, data)} closeSlider={closeSlider} sortcond={sortcond} ></GoalSubGoal>}
                                {tabKey == "2" && <GoalRelateInfo ecId={`${this && this.props && this.props.ecId || ''}_GoalRelateInfo@wzx3qd`} renderDetail={this.renderDetail} doCallBack={(type, optparams, data) => this.doCallBack(type, optparams, data)}></GoalRelateInfo>}
                                {tabKey == "3" && <GoalCommet ecId={`${this && this.props && this.props.ecId || ''}_GoalCommet@fotspa`} doCallBack={(type, optparams, data) => this.doCallBack(type, optparams, data)}></GoalCommet>}
                                {tabKey == "4" && <GoalOperateLog ecId={`${this && this.props && this.props.ecId || ''}_GoalOperateLog@f1s7yf`} renderDetail={this.renderDetail}></GoalOperateLog>}
                                {tabKey == "5" && <GoalShare ecId={`${this && this.props && this.props.ecId || ''}_GoalShare@bsq7c8`}></GoalShare>}
                            </div>
                            {subtagvisible && <TagChoiceBox ecId={`${this && this.props && this.props.ecId || ''}_TagChoiceBox@xlujh1`} visible={subtagvisible} checkedIds={checkedIds} onDialogClose={() => changeSubTagBoxVisible(false, 1)} onCallBack={(key, checklist) => this.checkList(key, checklist)} />}
                        </WeaNewScroll>
                    </WeaRightMenu>
                </div>
            </Spin>
        )
    }
}